import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import AutoImport from 'unplugin-auto-import/vite';
import Pages from 'vite-plugin-pages';
import WindiCSS from 'vite-plugin-windicss';

const { resolve } = require('path');

// https://vitejs.dev/config/
export default defineConfig({
    plugins: [
        react(),
        WindiCSS(),
        AutoImport({
            include: [/\.[tj]sx?$/],
            dts: true,
            imports: [
                // presets
                'react',
                'react-router-dom',
                // custom
                {
                    swr: [['default', 'useSwr']],
                    'framer-motion': ['motion'],
                    dayjs: [['default', 'time']],
                    '~react-pages': [['default', '$routes']],
                    '@/utils/router': [['default', 'withRouter']],
                    // '@/utils/fetcher': [['default','withHttp']],
                    '@/utils': ['axios', 'ObjectUtils'],
                },
            ],
            eslintrc: {
                enabled: true, // 默认false, true启用。生成一次就可以，避免每次工程启动都生成
                filepath: './.eslintrc-auto-import.json', // 生成json文件
                globalsPropValue: true,
            },
        }),
        Pages({
            extensions: ['tsx', 'jsx'],
            importMode: 'sync',
        }),
    ],
    server: {
        port: 3300,
        proxy: {
            '/api': {
                target: 'http://localhost:9090/',
                changeOrigin: true,
                rewrite: (path) => path.replace(/^\/api/, ''),
            },
        },
    },
    resolve: {
        alias: [{ find: '@', replacement: resolve(__dirname, 'src') }],
    },
    css: {
        modules: {
            generateScopedName: '[hash:base64]',
        },
    },
});
